package com.mocaris.android.gank.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.text.HtmlCompat
import com.mocaris.android.gank.R
import com.mocaris.android.gank.model.Article
import kotlinx.android.synthetic.main.item_list_android_article.view.*

class ArticleListAdapter(context: Context) : BaseRecyclerAdapter<Article>(context) {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            LayoutInflater.from(context).inflate(
                R.layout.item_list_android_article,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val article = getItem(position)
        holder.itemView.tv_title.text = article.title
        holder.itemView.tv_desc.text = HtmlCompat.fromHtml(article.desc, HtmlCompat.FROM_HTML_MODE_COMPACT)
        holder.itemView.tv_time.text = article.niceDate
        holder.itemView.tv_author.text = article.author
        holder.itemView.tv_chapter.text = "${article.superChapterName}>>${article.chapterName}"
    }

}